package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JMenuItem;

import gui.scheduler.*;

import util.*;

public class SystemTrayTest {
	public static void main(String[] args) throws Exception {
		CalendarInterface.initService();
		CalendarInterface.selectCalendar();
		if(SystemTray.isSupported()) {
			final SystemTray tray = SystemTray.getSystemTray();

			Image img = ImageIO.read(new File("icon.png"));
			final TrayIcon icon = new TrayIcon(img,"Tray Icon");
			PopupMenu menu = new PopupMenu();
			ActionListener listener = new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent ae) {
					switch(ae.getActionCommand().charAt(0)) {
					case 'O':
						icon.displayMessage("Meals have been removed", "The dates these meals " +
								"are scheduled for have been added to a skip list. They may be " +
								"removed from the skip list in the Scheduler.", TrayIcon.MessageType.INFO);
						break;
					case 'S':
						JFrame frame = new JFrame();
						frame.add(new ScheduleEditor());
						frame.pack();
						frame.setSize(650,455);
						frame.setMinimumSize(new Dimension(520,300));
						frame.setVisible(true);
						break;
					case 'Q':
						System.exit(0);
						break;
					}
				}
			};
			menu.add(new MenuItem("Options")).addActionListener(listener);
			menu.add(new MenuItem("Scheduler")).addActionListener(listener);
			menu.addSeparator();
			menu.add(new MenuItem("Quit")).addActionListener(listener);
			icon.setPopupMenu(menu);
			try {
				tray.add(icon);
			} catch (AWTException e) {
				e.printStackTrace();
			}
		} else {
			// Run as normal application in taskbar
		}
	}
}
